/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package cz.muni.fi.diplomka.servicelayer.gamelogic.resolver;

import cz.fi.muni.diplomka.common.enumeration.ResourceType;
import cz.muni.fi.diplomka.servicelayer.dto.City;
import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.CityManager;
import cz.muni.fi.diplomka.servicelayer.gamelogic.manager.CityResourcesManager;
import cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl.CityManagerImpl;
import cz.muni.fi.diplomka.servicelayer.gamelogic.managerimpl.CityResourcesManagerImpl;
import java.util.Calendar;
import java.util.GregorianCalendar;

/**
 * Class used for adding Resources to City based on production
 *
 * @author Jakub Kutil
 */
public class ResourceResolver {

    private static CityManager cityManager = new CityManagerImpl();
    private static CityResourcesManager cityResourcesManager = new CityResourcesManagerImpl();

    public static void main(String[] args) throws InterruptedException {
        while (true) {

            Calendar calendar = new GregorianCalendar();

            if (calendar.get(Calendar.MINUTE) == 0) {
                for (City city : cityManager.getAllCities()) {
                    for (ResourceType resource : ResourceType.values()) {
                        if (cityResourcesManager.getResourceProductionCount(city.getId(), resource) > 0) {
                            cityResourcesManager.increaseResource(city.getId(), resource, cityResourcesManager.getResourceProductionCount(city.getId(), resource));
                        }
                    }
                }
            } else {
                Thread.sleep(1000 * 60);
            }
        }
    }
}